<template>
    <div class="config">
        <Tabs type="card" :animated="false" style="background:#efeff1" v-model="tabName">
            <TabPane label="公司配置中心">
                <companyCfg :tableHeaders="TableHeaders" v-if="tabName==0"></companyCfg>
            </TabPane>

            <TabPane label="门店配置中心">
                <storeCfg :tableHeaders="TableHeaders" :currentTab="tabName" v-if="tabName==1"></storeCfg>
            </TabPane>

        </Tabs>
    </div>
</template>

<script>
import util from '@/libs/util'
import companyCfg from './companyCfg.vue'
import storeCfg from './storeCfg.vue'

export default {
  name: 'config_index',
  components: {
    companyCfg,
    storeCfg
  },
  data () {
    return {
      TableHeaders (type) {
        // const self = this;
        const publicKey = [
          {
            title: '电价',
            align: 'center',
            render: (h, params) => {
              return h.apply(null, this.renderStr('ele_price', params.row))
            }
          },
          {
            title: '电表付费模式',
            align: 'center',
            render: (h, params) => {
              return h.apply(null, this.renderStr('pay_type', params.row, 1))
            }
          },
          {
            title: '电表透支额度',
            align: 'center',
            render: (h, params) => {
              return h.apply(null, this.renderStr('overdraft_amount', params.row))
            }
          },
          {
            title: '断电提醒',
            align: 'center',
            render: (h, params) => {
              return h.apply(null, this.renderStr('low_warn', params.row))
            }
          }
        ]

        return {
          1: [
            {
              title: '门店',
              align: 'center',
              key: 'name'
            },
            ...publicKey
          ],

          2: [
            {
              title: '房源编号',
              align: 'center',
              key: 'name',
              render: (h, params) => {
                return h('span', params.row.home_name)
              }
            },
            {
              title: '房源地址',
              align: 'center',
              key: 'name',
              render: (h, params) => {
                let concatedLocation = util.concatLocation(params.row)
                return h('span', concatedLocation)
              }
            },
            {
              title: '门店',
              align: 'center',
              key: 'name',
              render: (h, params) => {
                let branch = params.row.branch
                return h('span', branch ? branch.name : '-')
              }
            },
            ...publicKey
          ],

          3: [
            {
              title: '房源地址',
              align: 'center',
              key: 'address',
              render: (h, params) => {
                return h('span', params.row.home && params.row.home.address)
              }
            },
            {
              title: '房间号',
              align: 'center',
              key: 'branch',
              render: (h, params) => {
                return h('span', params.row.room_name)
              }
            },
            {
              title: '门店',
              align: 'center',
              key: 'name',
              render: (h, params) => {
                let branch = params.row.branch
                return h('span', branch ? branch.name : '-')
              }
            },
            ...publicKey
          ]
        }[type]
      },
      tabName: 0
    }
  },

  methods: {}
}
</script>

<style lang="less" scoped>
</style>
